Skip to content

feat(iast): enable Code Security on Python 3.15 - #19698

Draft
avara1986 wants to merge 1 commit into
mainfrom
avara1986/iast-python-315-support
Draft

feat(iast): enable Code Security on Python 3.15#19698
avara1986 wants to merge 1 commit into
mainfrom
avara1986/iast-python-315-support

Conversation

@avara1986

@avara1986 avara1986 commented Aug 14, 2026

Copy link
Copy Markdown
Member

Description

Part of the Python 3.15 integration parity effort (parent tracker: #17809).

Closes #17843

APPSEC-69649

This PR enables IAST (Code Security) on Python 3.15.

There was no upstream blocker to bump. IAST's native extensions were never version-gated —
setup.py adds _iast._ast.iastpatch and _iast._taint_tracking._native under a platform-only
guard — so the only thing disabling Code Security on 3.15 was the runtime tuple in
ASMConfig._iast_supported. This widens it from < (3, 15, 0) to < (3, 16, 0) and corrects the
adjacent comment, which already said "3.6 to 3.13" while the code allowed 3.14.

Validating that gate surfaced two real bugs, both fixed here (see Bugs found below). The
eval() one matters: without it, turning IAST on for 3.15 would raise NameError inside customer
application code.

Changes

  • ddtrace/internal/settings/asm.py — widen _iast_supported to 3.15, fix the stale comment, add
    an AIDEV-NOTE recording that this is the only version gate and that the native extensions have
    no build-time gate.
  • ddtrace/appsec/_iast/taint_sinks/code_injection.py — add _resolve_caller_frame() so the
    code-injection aspect walks past wrapt's wrapper frame when locating the caller of eval().
  • tests/appsec/iast/aspects/test_slice_aspect_fixtures.py — accept CPython 3.15's reworded slice
    TypeError.
  • Two release notes (features for 3.15 support, fixes for the eval() bug).

Bugs found during validation

1. eval() raised NameError in application code whenever wrapt's C extension is absent.

_iast_coi resolved its caller with a fixed inspect.currentframe().f_back. That only lands on the
user's frame while wrapt uses its C FunctionWrapper, which creates no Python frame. wrapt ships no
cp315 wheel, so 3.15 falls back to the pure-Python implementation, which does add a frame — the
aspect then passed wrapt's globals/locals to eval(), so a lambda default like
eval("lambda v,fun=fun: not fun(v)") could not see fun.

This is pre-existing, not 3.15-specific. It reproduces on 3.14:

$ WRAPT_DISABLE_EXTENSIONS=1 python repro.py
NameError: name 'fun' is not defined      # before
OK: False                                 # after

2. CPython 3.15 reworded its slice error message, dropping the or None clause
(slice indices must be integers or None or have an __index__ method
slice indices must be integers or have an __index__ method). The aspect raises correctly; only the
test's asserted substring was stale.

Checklist

Adapted — several template items don't apply, because the blocker here was a runtime version check
rather than an upstream package pin:

  • Bumped upstream pin in riotfile.pyN/A, no upstream dependency involved.
  • Lifted max_version cap on the affected venv(s)N/A, the cap was a
    sys.version_info check, not a riot cap.
  • Ran riot generate and committed lockfilesN/A, riotfile.py is unchanged. The
    IAST venvs already use select_pys(), so they pick up 3.15 automatically once it joins
    SUPPORTED_PYTHON_VERSIONS.
  • Ran the suites on 3.15 — see Testing. Note this could not go through
    scripts/run-tests; see the caveat there.
  • Updated supported_versions.jsonN/A, that file tracks per-integration package
    versions and has no IAST row.
  • Release notes added under releasenotes/notes/.

Testing

Built CPython 3.15.0rc1+dev via pyenv install 3.15-dev (matching .python-version and
.gitlab/testrunner.yml), stacked #17849 in a scratch worktree to get past the import ddtrace
blocker, and locally bumped requires-python so pip install -e . would run. Neither of those
local-only edits is in this PR.

Check Result
pip install -e . on 3.15 pass — _native.cpython-315*.so and iastpatch.cpython-315*.so both produced
Native C++ gtest (appsec_iast_native) 186/186 pass
tests/appsec/iast/ 19,625 passed, 0 failed, 59 skipped, 18 xfailed
tests/appsec/iast_tdd_propagation/ 1 passed, 6 skipped (all pre-existing >= (3, 14) skips)
appsec_iast_default on 3.14 (riot) pass
appsec_iast_default on 3.13 (riot) pass

CMake was confirmed to resolve the right interpreter (3.15 headers + libpython3.15.so) rather than
silently picking the system Python.

Notable positives: test_template_string_aspect.py (PEP-750 t-strings, 3.14+) collects and
passes
on 3.15, exercising the PY_VERSION_HEX >= 0x030E0000 branch of
utils/string_utils.cpp; and test_native_taint_range.py's refcount assertions hold under 3.15.

Why raw pytest for the 3.15 leg. AGENTS.md says never to invoke pytest directly, but riot
cannot target 3.15 at all today: riotfile.py:SUPPORTED_PYTHON_VERSIONS and
scripts/gen_gitlab_config.py:ALL_PYTHON_VERSIONS both stop at 3.14, and there are zero 3.15
lockfiles. The env=/pkgs= blocks were replicated by hand from the appsec_iast_default venv.
Both 3.13/3.14 regression runs went through scripts/run-tests as normal. Excluded on 3.15:
test_grpc_iast.py (grpcio has no cp315 wheel).

Risks

Additional Notes

Findings handed to the Python 3.15 migration owners — all outside this PR's scope:

  • PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 breaks the 3.15 build. It forces limited-API mode,
    which excludes PyContextVar_New/Get/Set, so src/native/contextvar.rs fails with E0425.
    pyo3 0.28 supports 3.15 natively, so the flag is counterproductive there.
  • tests/conftest.py blocks every test on 3.15. The autouse enable_crashtracking fixture
    asserts crashtracking.is_started(), but setup.py drops the crashtracker Rust feature on 3.15,
    so is_available is False and start() returns early. Needs
    yield platform.system() == "Linux" and crashtracking.is_available.
  • pip<25 cannot be satisfied on 3.15. appsec_iast_default pins it to work around IAST
    first-party detection, but pip 24.x fails to import on 3.15 (typing.no_type_check_decorator was
    removed). Resolving the iastpatch.c TODO is a prerequisite for that suite on 3.15.
  • On the chore: wrapping context support for Python 3.15 #17849 branch, ddtrace/internal/coverage/import_instrumentation_py3_12.py imports
    INJECTION_ASSEMBLY, which no longer exists in ddtrace.internal.bytecode_injection. This breaks
    ddtrace's own pytest plugin on all Python versions, not just 3.15.
  • The 3.14 release notes (python-314-f80c8356eaaf8392.yaml, more-314-suites-bf99a7d7ef1b2128.yaml)
    still list IAST as not working on 3.14, which was already inaccurate before this PR. Left
    untouched, since both shipped in v3.16.0rc1.

🤖 Generated with Claude Code

Lifts the IAST version gate in ASMConfig from < 3.15 to < 3.16 so
DD_IAST_ENABLED takes effect on Python 3.15 instead of being silently
ignored. No build change is needed: the IAST native extensions are gated
on platform only, never on Python version.

Validated on Python 3.15.0rc1+dev: both native extensions build for
cp315, the native taint-tracking gtest suite passes 186/186 against real
3.15 headers, and tests/appsec/iast/ is green (19,625 passed). No
regression on 3.13 or 3.14.

Two bugs surfaced during validation and are fixed here:

- The code-injection aspect resolved the wrong caller scope, raising
  NameError in application code that calls eval(). It assumed a fixed
  inspect.currentframe().f_back depth, which only holds while wrapt uses
  its C extension. wrapt has no cp315 wheel, so 3.15 falls back to the
  pure-Python FunctionWrapper, which adds a frame. This is pre-existing
  rather than 3.15-specific: it reproduces on 3.14 with
  WRAPT_DISABLE_EXTENSIONS=1.
- CPython 3.15 dropped the "or None" clause from its slice TypeError,
  so test_slice_aspect_fixtures.py asserted a message that no longer
  exists.

IAST on 3.15 stays unreachable until the tracer wrapping work (#17849)
and the requires-python / riot matrix bumps land, so this is correct but
inert until then.

Closes #17843
APPSEC-69649

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 5 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.contrib.internal.django.patch -> ddtrace.contrib.internal.django.response -> ddtrace.contrib.internal.django.patch
ddtrace.contrib.internal.pytorch._distributed -> ddtrace.contrib.internal.pytorch._rank_root -> ddtrace.contrib.internal.pytorch._distributed
ddtrace.llmobs -> ddtrace.llmobs._evaluators -> ddtrace.llmobs._evaluators.format -> ddtrace.llmobs._experiment -> ddtrace.llmobs
ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector
ddtrace.appsec._asm_request_context -> ddtrace.appsec._iast._iast_request_context_base -> ddtrace.appsec._iast._iast_env -> ddtrace.appsec._iast.reporter -> ddtrace.appsec._exploit_prevention.stack_traces -> ddtrace.appsec._asm_request_context

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

ddtrace/appsec/_iast/taint_sinks/code_injection.py                      @DataDog/asm-python
ddtrace/internal/settings/asm.py                                        @DataDog/asm-python
releasenotes/notes/iast-fix-eval-caller-scope-74305dc0d86abc22.yaml     @DataDog/apm-python
releasenotes/notes/iast-python-315-support-62b7d764f5b5b5b0.yaml        @DataDog/apm-python
tests/appsec/iast/aspects/test_slice_aspect_fixtures.py                 @DataDog/asm-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 255 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 255 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=134)
ddtrace.llmobs._integrations.google_adk -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.llmobs._integrations.bedrock_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)
ddtrace.debugging._signal.model -×-> ddtrace.trace  (product:debugging -> product:tracing, score=132)
ddtrace.llmobs._integrations.litellm -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=132)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

@pr-commenter

pr-commenter Bot commented Aug 14, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-08-14 12:51:18

Comparing candidate commit e7ac64a in PR branch avara1986/iast-python-315-support with baseline commit 5fe261d in branch main.

Found 0 performance improvements and 7 performance regressions! Performance is the same for 612 metrics, 10 unstable metrics.

scenario:httppropagationinject-ids_only

  • 🟥 execution_time [+2.789µs; +2.973µs] or [+13.160%; +14.030%]

scenario:iastaspects-lower_aspect

  • 🟥 execution_time [+32.238µs; +36.308µs] or [+14.023%; +15.794%]

scenario:iastaspects-title_aspect

  • 🟥 execution_time [+25.062µs; +28.907µs] or [+9.673%; +11.157%]

scenario:iastaspectsospath-ospathbasename_aspect

  • 🟥 execution_time [+81.734µs; +86.537µs] or [+20.053%; +21.232%]

scenario:span-start

  • 🟥 execution_time [+1.121ms; +1.309ms] or [+7.137%; +8.338%]

scenario:telemetryaddmetric-1-count-metric-1-times

  • 🟥 execution_time [+377.074ns; +418.307ns] or [+14.477%; +16.060%]

scenario:tracer-small

  • 🟥 execution_time [+29.009µs; +31.605µs] or [+8.296%; +9.039%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[3.15] IAST 3.15

1 participant